home *** CD-ROM | disk | FTP | other *** search
- unit TestUnit;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls,
- AAByteQ;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- ListBox1: TListBox;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- const
- TestOpCount = 20;
- TestOps : array [1..TestOpCount] of integer =
- ( 45, 12, 28, -45, 59, -12, -28, 5, 61, 11,
- 23, -59, 37, -5, -61, -11, -23, 15, -37, -15);
- TestData : string[TestOpCount] =
- 'ABCADBCEFGHDIEFGHJIJ';
-
- procedure CreateBuffer(aCount : integer; aChar : char; aBuf : pointer);
- begin
- FillChar(aBuf^, aCount, aChar);
- end;
-
- procedure CheckBuffer(aCount : integer; aChar : char; aBuf : pointer);
- var
- i : integer;
- begin
- for i := 0 to pred(aCount) do
- if (PChar(aBuf)[i] <> aChar) then
- raise Exception.Create('Bad character');
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- MyByteQ : TaaByteQueue;
- Buffer : pointer;
- i : integer;
- begin
- MyByteQ := TaaByteQueue.Create;
- try
- GetMem(Buffer, 64);
- try
- for i := 1 to TestOpCount do begin
- if (TestOps[i] > 0) then begin
- CreateBuffer(TestOps[i], TestData[i], Buffer);
- MyByteQ.Put(Buffer^, TestOps[i]);
- ListBox1.Items.Add(Format('Put %d %s''s Count=%d Cap=%d',
- [TestOps[i], TestData[i],
- MyByteQ.Count, MyByteQ.Capacity]));
- end
- else begin
- MyByteQ.Get(Buffer^, -TestOps[i]);
- ListBox1.Items.Add(Format('Get %d %s''s Count=%d Cap=%d',
- [-TestOps[i], TestData[i],
- MyByteQ.Count, MyByteQ.Capacity]));
- CheckBuffer(-TestOps[i], TestData[i], Buffer);
- end;
- end;
- finally
- FreeMem(Buffer, 64);
- end;
- finally
- MyByteQ.Free;
- end;
- end;
-
- end.
-